{extend name="../admin/common/base" /}
{block name="body"}
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <ul class="layui-tab-title">
        <li {eq name="$type" value="1"} class="layui-this" {/eq}><a href="{:url('material/addMaterial',['type'=>1])}">新增图片</a></li>
        <li ><a href="{:url('material/addNews')}">新增图文</a></li>
        <li {eq name="$type" value="3"} class="layui-this" {/eq}><a href="{:url('material/addMaterial',['type'=>3])}">新增音频</a></li>
        <li {eq name="$type" value="4"} class="layui-this" {/eq}><a href="{:url('material/addMaterial',['type'=>4])}">新增视频</a></li>
        <li ><a href="{:url('material/addNews',['type'=>4])}">新增活动</a></li>
        <li ><a href="{:url('material/addNews',['type'=>1])}">新增文本</a></li>

    </ul>
    <div class="layui-tab-content">
        {switch name="type"}
        {case value="1"}
        <form class="layui-form"  >
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label">图片：</label>
                        <div class="layui-input-block">
                            <style>
                                .rhaphp-hook-upload-image{overflow: hidden;}  .upload-imgs{border: 1px solid #e6e6e6; padding: 3px; display: inline-block; margin-right: 5px;}  .upload-imgs img {width: 150px; height: 90px;}  .upload-imgs-del{cursor: pointer;position: absolute;  font-size: 18px;}
                            </style>
                            <div class="rhaphp-hook-upload-image">
                                <div class="rhaphp-upload-thumb" style="padding: 5px; border: #e6e6e6 solid 1px; ">
                                    <img class="form_m_image" src="__STATIC__/images/def.jpg" width="150" height="90">
                                </div>
                                <div class="rhaphp-upload" style="margin-bottom: 10px; margin-left: 5px;  ">
                                    <input style="display: none" value="" name="m_image" type="text">
                                    <button style="margin-bottom: 5px;" type="button" class="layui-btn layui-btn-primary" id="up_m_image"><i class="layui-icon"></i>上传图片</button><input class="layui-upload-file" name="image" type="file">
                                </div>
                            </div>
                            <script>
                                layui.use('upload', function(){
                                    var load;
                                    var upload = layui.upload;
                                    var uploadInst = upload.render({
                                        elem: '#up_m_image'
                                        ,url: "/mp/upload/uploadimg.html"
                                        ,accept: 'images' //普通文件
                                        ,field:'image'
                                        ,before: function(input){
                                            load = layer.load(1);
                                        }
                                        ,done: function(res){
                                            if(res.code==0){
                                                $('input[name="m_image"]').val(res.data.src)
                                                $('.form_m_image').attr('src',res.data.src);
                                                layer.alert('上传成功');
                                                layer.close(load);
                                            }else{
                                                layer.close(load);
                                                layer.alert(res.msg);
                                            }
                                        }
                                        ,error: function(){
                                            //请求异常回调
                                        }
                                    });
                                });
                            </script>                        </div>
                    </div>
                </div>

            </div>
        </form>
        {/case}
        {case value="2"}
        <form class="layui-form"  >
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label">图片：</label>
                        <div class="layui-input-block">
                            {:hook('Upload',['type'=>'image','name'=>'m_image'])}
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="addMaterial">立即提交</button>
                    </div>
                </div>
            </div>
        </form>
        {/case}
        {case value="3"}
        <form class="layui-form"  >
            <div class="layui-form-item">
                <label class="layui-form-label">语音名称</label>
                <div class="layui-input-block">
                    <input type="text" name="voice_title" value="" placeholder="请输入标题" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label">音频：</label>
                        <div class="layui-input-block">
                            {:hook('Upload',['type'=>'voice','name'=>'m_voice','bt_title'=>'上传语音'])}
                            <p class="tip_for_p">临时语音只支持amr/mp3格式,大小不超过为2M,长度不超过60秒,永久语音只支持mp3/wma/wav/amr格式,大小不超过为5M,长度不超过60秒</p>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="addMaterial">立即提交</button>
                    </div>
                </div>
            </div>
        </form>
        {/case}
        {case value="4"}
        <form class="layui-form"  >
            <div class="layui-form-item">
                <label class="layui-form-label">视频标题</label>
                <div class="layui-input-block">
                    <input type="text" name="video_title" value="" placeholder="请输入标题" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">视频</label>
                <div class="layui-input-block">
                    {:hook('Upload',['type'=>'video','name'=>'m_video','bt_title'=>'上传视频'])}
                    <p class="tip_for_p">临时视频只支持mp4格式,大小不超过为10M,永久视频只支持rm/rmvb/wmv/avi/mpg/mpeg/mp4格式,大小不超过为20M</p>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">描述内容</label>
                <div class="layui-input-block">
                    <textarea name="video_content" placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="addMaterial">立即提交</button>
                </div>
            </div>
        </form>
        {/case}


        {/switch}
    </div>
</div>


<script>
    layui.use('form', function(){
        var form = layui.form;
        form.on('submit(addMaterial)', function(data){

            var loadIndex = layer.load(1);
            $.post('',data.field,function (res) {
                layer.close(loadIndex);

                if(res.status==2){
                    layer.confirm(res.msg, {
                        btn: ['是','不'] //按钮
                    }, function(){
                        var l_index=layer.load(2);
                        data.field.check_repeat = 1;
                        $.post('',data.field,function (res) {
                            layer.close(l_index);
                            layer.alert(res.msg)

                        });


                    }, function(){

                    });
                }else{
                    layer.alert(res.msg)
                }


            });
            return false;
        });

    });
</script>

{/block}